package io.renren.modules.receiveJobDemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.receiveJobDemo.dao.TaskAssignmentDao;
import io.renren.modules.receiveJobDemo.dto.TaskAssignmentDTO;
import io.renren.modules.receiveJobDemo.entity.TaskAssignmentEntity;
import io.renren.modules.receiveJobDemo.entity.UserEntity;
import io.renren.modules.receiveJobDemo.service.TaskAssignmentService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 任务分配表
 *
 * @author Musk.gqh 1259757804@qq.com
 * @since 1.0.0 2024-05-20
 */
@Service
public class TaskAssignmentServiceImpl extends CrudServiceImpl<TaskAssignmentDao, TaskAssignmentEntity,
        TaskAssignmentDTO> implements TaskAssignmentService {

    @Resource
    private TaskAssignmentDao taskAssignmentDao;

    @Override
    public QueryWrapper<TaskAssignmentEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<TaskAssignmentEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public List<UserEntity> queryUsername() {
        return taskAssignmentDao.queryUsername();
    }

    @Override
    public void updateStartById(Integer id) {
        TaskAssignmentEntity entity = new TaskAssignmentEntity();
        entity.setId(id);
        entity.setFlag(1);//设置为开打
        taskAssignmentDao.updateByFlag(entity);
    }

    @Override
    public void updateEndById(Integer id) {
        TaskAssignmentEntity entity = new TaskAssignmentEntity();
        entity.setId(id);
        entity.setFlag(2);//设置为打完
        taskAssignmentDao.updateByFlag(entity);
    }

    @Override
    public String queryRoleNameIdByToken(String token) {
        return taskAssignmentDao.queryRoleNameIdByToken(token);
    }

    @Override
    public String queryUsernameByToken(String token) {
        return taskAssignmentDao.queryUsernameByToken(token);
    }


}